﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DataReader对象 : System.Web.UI.Page
{
    protected string connstr;
    protected string sql;
    
    protected void Page_Load(object sender, EventArgs e)
    {
       // Comm.maina.Equals(sql);
        connstr = ConfigurationSettings.AppSettings["SqlConn"];
        sql = "select * from zhuanti";
        SqlConnection MyConn = new SqlConnection(connstr);
        SqlCommand ObjCommand = new SqlCommand(sql, MyConn);
        MyConn.Open();
        SqlDataReader DataReade对象 = ObjCommand.ExecuteReader();
                                                //ExecuteNonQuery()可以执行Insert;DELETE;;等SQL语句.
                                                //ExecuteScalar()返回第个结果集中的,第一行的第一列记录.
                                                //ExecuteXMLReader()返回XmlReader对象,要求查询或存储过程以XML格式返回结果,只有SQL2000以上有.
        Response.Write(DataReade对象);
        int index = 0;
        string output = "<table>";

        while (DataReade对象.Read()) 
        
        {
            output += "<tr>"+"<td width=30>" + (++index).ToString()
            +"</td><td>" + DataReade对象["Content"].ToString()
            +"</td></tr>";
        }
        DataReade对象.Close();//要关闭哦
        MyConn.Close();//要关闭哦
        output += "</table>";
        Response.Write(output);
    }
}
